package com.hsqn.controller;

import com.hsqn.service.WorkService;
import hsqn.pojo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("work")
@RestController
@Tag(name = "工单管理")

public class WorkController {
    @Autowired
    WorkService workService;

    @PostMapping("insert")
    @Operation(summary = "添加工单", description = "新增工单信息（包含订单编号、老人 ID 等核心字段）", responses = {@ApiResponse(description = "成功", responseCode = "200", content = @Content(schema = @Schema(implementation = Result.class))), @ApiResponse(description = "失败", responseCode = "400")})
    public Result insert(@Parameter(name = "order_no", description = "订单编号") @RequestParam String order_no, @Parameter(name = "elderly_id",
                                 description = "老人 ID") @RequestParam int elderly_id, @Parameter(name = "O_type", description = "订单类型（数字标识）")
                         @RequestParam int O_type, @Parameter(name = "S_type", description = "服务类型") @RequestParam String S_type, @Parameter
                                 (name = "content", description = "工单内容") @RequestParam String content,
                         @Parameter(name = "time", description = "工单时间（格式建议：yyyy-MM-dd HH:mm:ss）")
                         @RequestParam String time, @Parameter(name = "createid", description = "创建人 ID") @RequestParam int createid) {
        workService.insert(order_no, elderly_id, O_type, S_type, content, time, createid);
        return Result.success();
    }

    @PostMapping("update_executor")
    @Operation(summary = "更新执行人", description = "更新工单执行人信息", responses = {@ApiResponse(description = "成功", responseCode = "200",
            content = @Content(schema = @Schema(implementation = Result.class))), @ApiResponse(description = "失败", responseCode = "400")})
    public Result update_executor(@Parameter(name = "order_no", description = "工单编号") @RequestParam String order_no,
                                  @Parameter(name = "executor_id", description = "执行人 ID") @RequestParam int executor_id) {
        workService.update_executor(order_no, executor_id);
        return Result.success();
    }
}